<template>
  <FrontSideTable
    dataUrl="/param/treatment/getList"
    addUrl="/param/treatment/add"
    editUrl="/param/treatment/edit"
    deleteUrl="/param/treatment/delete"
    tableTitle="处治方法列表"
    searchHint="输入关键字搜索，多个关键字用空格隔开"
    :columns="columns"
    :form="form"
    :rules="rules"
    :searchProps="searchProps"
    @beforeAdd="beforeAdd"
    @beforeEdit="beforeEdit"
    @onCreated="onCreated">
    <template slot="form">
      <el-form-item label="处治方法" prop="name">
        <el-input v-model="form.name" placeholder="输入处治方法名称"></el-input>
      </el-form-item>
      <el-form-item label="处治费率" prop="rate">
        <el-input type="number" v-model.number="form.rate" placeholder="输入处治费率"></el-input>
      </el-form-item>
      <el-form-item label="工程量单位" prop="unit">
        <el-input v-model="form.unit" placeholder="输入处治工程量单位"></el-input>
      </el-form-item>
      <el-form-item label="顺序号" prop="sortNo">
        <el-input type="number" v-model.number="form.sortNo" placeholder="输入顺序号，默认自定递增"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" v-model="form.notes"></el-input>
      </el-form-item>
    </template>
  </FrontSideTable>
</template>

<script>
  import FrontSideTable from "../../template/FrontSideTable.vue"
  import {clearFields} from "../../../assets/js/utils/ObjectUtils"
  import {floatValidator, intValidator} from "../../../assets/js/utils/ValidateUtils"

  let oldName = "";

  export default {
    name: "TreatmentMaintenance",
    data() {
      //处治方法名校验
      let nameValidator = (rule, value, callback) => {
        if (value === oldName) {
          callback();
        } else if(this.dataList.some(item=>item.name === value)) {
          callback(new Error("处治方法名称重复"));
        } else {
          callback();
        }
      };

      return {
        dataList:[],
        form:{
          name:"",
          rate:"",
          unit:"",
          notes:"",
          sortNo:""
        },
        searchProps:["name"],
        columns:[
          {prop:"sortNo", label:"顺序号", sortable:"custom", width:"100"},
          {prop:"name", label:"处治方法名"},
          {prop:"rate", label:"处治费率(元)"},
          {prop:"unit", label:"费率计算单位"},
          {prop:"notes", label:"备注"}
        ],
        rules:{
          name:[
            {required:true, message:"请输入处治方法名称", trigger:"blur"},
            {validator:nameValidator, trigger:"blur"}
          ],
          rate:[
            {required:true, type:"number", message:"请输入处治费率", trigger:"blur"},
            {validator:floatValidator, trigger:"blur"}
          ],
          unit:[
            {required:true, message:"请输入费率计算单位", trigger:"blur"}
          ],
          sortNo:[{validator:intValidator, trigger:"blur"}]
        }
      }
    },
    methods:{
      onCreated(dataList) {
        this.dataList = dataList;
      },
      beforeAdd() {
        oldName = "";
        clearFields(this.form);
      },
      beforeEdit(data) {
        oldName = data.name;
        this.form = {...data};
      }
    },
    components:{FrontSideTable}
  }
</script>



// WEBPACK FOOTER //
// TreatmentMaintenance.vue?09349a85